<template>
  <dl class="list">
    <template v-for="(q, qIndex) in questions">
      <component
        :is="renderTitleComp"
        v-if="q.QuestionId === ''"
        :key="'qt' + q.QuestionTypeId"
        :q-index="qIndex"
        :name="q.QuestionTypeName"
        :is-result-page="isResultPage"
      />
      <template v-else>
        <component
          :is="renderTitleComp"
          v-if="showTitle(q, qIndex)"
          :key="'title' + q.QuestionId"
          :q-index="qIndex"
          :name="q.QuestionTypeName"
          :is-result-page="isResultPage"
        />
        <component
          :is="renderItemComp"
          :key="'item' + q.QuestionId"
          :q-index="qIndex"
          :question="q"
          :is-result-page="isResultPage"
          :show-correctness="!!showCorrectness"
        />
      </template>
    </template>
  </dl>
</template>

<script lang="ts">
import Vue from 'vue'
import { AppInfo } from '@/lib/appMethods'
export default Vue.extend({
  components: {
    TestListTitle: () => import(/* webpackChunkName: "examTest" */ './TestListTitle.vue'),
    TestListItemH5: () => import(/* webpackChunkName: "examTest" */ './TestListItemH5.vue'),
  },
  // eslint-disable-next-line vue/require-prop-types
  props: ['questions', 'showCorrectness'],
  data () {
    return {
      isResultPage: this.$route.name === 'examResult',
    }
  },
  computed: {
    renderTitleComp (): string {
      return 'TestListTitle'
    },
    renderItemComp (): string {
      return 'TestListItemH5'
    },
  },
  methods: {
    showTitle (q: any, index: any) {
      const { Type, ShowType } = this.$route.query
      /* eslint-disable eqeqeq */
      // if (ShowType == '0' && Type != '3' && Type != '4' && AppInfo.isApp) {
      //   return false
      // }
      if (index === 0) {
        return true
      }
      if (q.QuestionTypeId !== this.questions[index - 1].QuestionTypeId) {
        return true
      }
      return false
    },
  },
})
</script>

<style lang="scss" scoped>
.list {
  padding: 14px 0;
}
</style>
